<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>HR 邮箱验证</title>  
</head>
<body>
<div class="ui segment" id="n-page">

        <div class="ui segment" id="n-content">
            <form class="ui form">
                
                
                <div class="field">
                    <label>手机号码</label>
                    <div class="ui input">
                        <input type="text" name="email" id="email" placeholder="请输入您的手机号" value="${employer.email}">
                    </div>
                </div>
                <div class="field">
                    <label>验证码</label>
                    <div class="ui input">
                    <input type="text" name="code" id="code" placeholder="请输入验证码" value="${employer.code}">
                    &nbsp;<div class="ui button active dog" id="sendEmail">发送</div>
                    </div>
                </div>
                
                <input type="hidden" name="hrid" id="hrid" value="${employer.id}"/>
                <!--
                <input type="hidden" name="openid" id="openid" value="${employer.openid}"/>
                -->
            </form>        
        </div>
        <!--
        <div class="ui segment" id="btn-next2">
            <div class="fluid ui button" id="next">下一步</div>
        </div>
        -->
        <div class="ui center aligned segment" id="choice-buttons"> 
            <div class="two ui buttons"> 
                <div class="ui button active dog" id="next">下一步</div> 
                <div class="ui button active dog" id="closeit">回首页</div> 
            </div>
        </div>
</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu',
        'closeWindow']  
});

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }

            if($(this).attr('id') == 'next') {
               
                var email = $("#email").val();
                var code = $("code").val();
                var hrid  = $("#hrid").val();
                if(!name || name=="") {
                    alert("您必须输入您的名字");
                    return false;
                }
                if(!email) {
                    alert("您必须输入电子邮箱");
                    return false;
                }
                var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm;
                if(!re.test(email)) {
                    alert("您必须输入合格的电子邮箱");
                    return false;
                }

                $(this).addClass('disabled');
                var that = this;

                var postUrl = '${ctx}/wechat/employer/preRegist.do';
                var param = {};
                param['code']  = code;
                param['email']  = email;
                if (hrid) { 
                    param['id'] = hrid;
                }

                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(data) { 
                        if(data.errorcode=="0"){
                            var employer = data.data;
                            location.href = '${ctx}/wechat/company/toCreate.page?employerId='+employer.id;
                            return;
                        }  else if(data.errorcode=="1") {
                            alert(data.msg);
                            location.href = '${ctx}/wechat/employer/main.page';
                            return;
                        } else {
                            alert(data.msg);
                            $(that).removeClass('disabled');
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                        $(that).removeClass('disabled');
                    } 
                });
            }
        } 
    };

    $(document).ready(function() { 
        wx.ready(function() {
            $('.button').on('click', handler.activate);

            wx.hideOptionMenu();
        });
    });

</script>
</body>
</html>